package glub.hlzds.mijia;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class MiJia {

    @RequestMapping(value="/getData",method= RequestMethod.POST)
    @ResponseBody
    public String getData(@RequestParam(name = "url",required=false) String url,@RequestParam(name = "data",required=false) String data,@RequestParam(name = "ssecurity",required=false) String ssecurity,@RequestParam(name = "cookie",required=false) String cookie)throws Exception{
        return XiaoMi.apiServer(url,data,ssecurity,cookie);
    }

    @RequestMapping(value="/procedureSwitch",method= RequestMethod.POST)
    @ResponseBody
    public String procedureSwitch(@RequestParam(name = "type",required=false) String type,@RequestParam(name = "device",required=false) String device,@RequestParam(name = "flag",required=false) String flag,@RequestParam(name = "ssecurity",required=false) String ssecurity,@RequestParam(name = "cookie",required=false) String cookie)throws Exception{
//        System.out.println(cookie);

        if("sd".equals(type)){
            String sceneList = XiaoMi.apiServer("/scene/list","{\"st_id\":30}",ssecurity,cookie);
            JSONObject sl = JSONObject.parseObject(sceneList);
            return XiaoMi.shoudong(sl,device,flag,ssecurity,cookie);
        }else{
            String sceneList = XiaoMi.apiServer("/scene/list","{\"st_id\":15}",ssecurity,cookie);
            JSONObject sl = JSONObject.parseObject(sceneList);
            return XiaoMi.kongzhi(sl,device,flag,ssecurity,cookie);
        }
    }
}
